package com.example.hotelmanagement.controller;

import com.example.hotelmanagement.entity.Result;
import com.example.hotelmanagement.entity.Staff;
import com.example.hotelmanagement.service.StaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/staff")
public class StaffController {

    @Autowired
    private StaffService staffService;

    @GetMapping
    public Result getAllStaff() {
        return Result.ok(staffService.findAll());
    }

    @GetMapping("/{id}")
    public Result getStaffById(@PathVariable Integer id) {
        Staff staff = staffService.findById(id);
        return staff != null ? Result.ok(staff) : Result.error();
    }

    @PostMapping
    public Result createStaff(@RequestBody Staff staff) {
        return Result.ok(staffService.save(staff));
    }

    @PutMapping
    public Result updateStaff(@RequestBody Staff staff) {
        return Result.ok(staffService.update(staff));
    }

    @DeleteMapping("/{id}")
    public Result deleteStaff(@PathVariable Integer id) {
        return Result.ok(staffService.delete(id));
    }
}